package com.hup.sidebar.framework.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.provider.Settings;

/**
 * @author hugan
 * @date 2022/6/3
 */
public class PermissionUtil {

    /**
     * @return 有无悬浮窗权限
     */
    @SuppressLint("ObsoleteSdkInt")
    public static boolean hasOverlayPermission(Context context) {
        boolean result = true;
        if (Build.VERSION.SDK_INT >= VERSION_CODES.M && !Settings.canDrawOverlays(context)) {
            result = false;
        }
        return result;
    }

    /**
     * 调整到权限申请页面
     * flyme:bug?不能直接打开到app选项
     */
    public static void acquireOverlayPermission(Activity activity, int requestCode) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + BuildConfigUtil.applicationId()));
        activity.startActivityForResult(intent, requestCode);
    }


}
